package leetcode.每日一题;

import org.junit.Test;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author ：zsy
 * @date ：Created 2022/10/19 9:49 AM
 * @description：
 */
public class 无法吃午餐的学生数量 {
    @Test
    public void test() {
        System.out.println(new Solution().countStudents(new int[]{1,1,0,0}, new int[]{0,1,0,1}));
    }

    class Solution {
        public int countStudents(int[] students, int[] sandwiches) {
            int s1 = Arrays.stream(students).sum();
            int s0 = students.length - s1;
            for (int i = 0; i < sandwiches.length; i++) {
                if (sandwiches[i] == 0 && s0 > 0) {
                    s0--;
                } else if (sandwiches[i] == 1 && s1 > 0) {
                    s1--;
                } else {
                    break;
                }
            }
            return s0 + s1;
        }
    }
}
